<link rel='stylesheet' href='<?php echo base_url();?>css/calendar.css' title='calendar'>

<script language="javascript" src="<?php echo base_url();?>js/calendar.js"></script>

<script language="javascript">

//***** Function formating the Date for inputbox *****

function fnSetDateFormat(oDateFormat)
{
	oDateFormat['FullYear'];		//Example = 2007
	oDateFormat['Year'];			//Example = 07
	oDateFormat['FullMonthName'];	//Example = January
	oDateFormat['MonthName'];		//Example = Jan
	oDateFormat['Month'];			//Example = 01
	oDateFormat['Date'];			//Example = 01
	oDateFormat['FullDay'];			//Example = Sunday
	oDateFormat['Day'];				//Example = Sun
	oDateFormat['Hours'];			//Example = 01
	oDateFormat['Minutes'];			//Example = 01
	oDateFormat['Seconds'];			//Example = 01

	var sDateString;
	
	return sDateString;
}

</script>
<script>
   $(document).ready(function(){
       $("#category_id").change(function(){
           var category_id = $(this).val();
           $.ajax({
	    	   type: "POST",
	    	   url:"<?php echo  base_url();?>model/get_version",
	    	   data: "category_id="+category_id,
	    	   success: function(msg){
	    		   $("#version_id").html("");
		    	   $("#version_id").html(msg);
	    	   }
	    	});
       })

       $(".add_mod").click(function(){
           var str = $("#sttr").val();
           $(this).parents(".receive").append(str);
           var num = $("#num").val();
    	   var n = num.split("_");
    	   var i = ++n[1];
    	   var na = "version_"+i;
    	   $(this).parents(".receive").children(".total:last-child").children(".category").children("li:last-child").children(".version_ul").children("li:last-child").children(".version").attr('id',na);
 	       var num = $("#num").val(na);
       }) 

       $(".del_mod").click(function(){
    	   $(".receive").children(".total:eq(1)").remove();

       })

       $("#submit").click(function(){
           var codes = $("#codes").val();
           if(codes==""){
              alert("接收单据号不能空！");
              return false;
           }
       })
   })
   
   
   function num(va){
	   var cate = $(va).parents("li").parents(".version_ul").parents("li").children(".category_id").val();
       if(cate==""){
 	          alert("请选择类别!");
 	          return false;
      }
   }
   function add(vsa){
//取得型号和类别所选取的值，然后给版本号和数量input 赋name
	  var mod_val = $(vsa).parents(".total").children(".mod").children(".mod_id").val();
	  var cate_val = $(vsa).parents(".version_ul").parents("li").children(".category_id").val();
	   var num = $("#num").val();
	   var n = num.split("_");
	   var i = ++n[1];
	   var na = "version_"+i;
	  if(mod_val==""){
          alert("请选择型号!");
          return false;
	  }
	  if(cate_val==""){
          alert("请选择类别!");
          return false;
	  }
      var str = $(vsa).parents(".version_ul").children("li:eq(1)").html();
      var child = "<li>"+str+"</li>";
      $(vsa).parents(".version_ul").append(child);
      $(vsa).parents(".version_ul").children("li:last-child").children(".version").attr('id',na);
      var num = $("#num").val(na);
   }

   function del(vsa){
	  $(vsa).parents(".version_ul").children("li:eq(2)").remove();
   }	   

   function add_cate(mod){
	   var str = $(mod).parents(".total").children(".category").children("li:eq(0)").html();
	   var m = $(mod).parents(".total").children(".mod").children(".mod_id").val();
       var child = $("#str").val();
       var num = $("#num").val();
	   var n = num.split("_");
	   var i = ++n[1];
	   var na = "version_"+i;
       $(mod).parents(".total").children(".category").append(child);
       $.ajax({
    	   type: "POST",
    	   url:"<?php echo  base_url();?>model/get_category",
    	   data: "mod_id="+m,
    	   success: function(msg){
        	   $(mod).parents(".total").children(".category").children("li:last-child").children(".category_id").html("");
        	   $(mod).parents(".total").children(".category").children("li:last-child").children(".category_id").html(msg);
        	   $(mod).parents(".total").children(".category").children("li:last-child").children(".version_ul").children("li:last-child").children(".version").attr('id',na);
     	       var num = $("#num").val(na);
    	   }
    	});
   }

   function del_cate(mod){
	   $(mod).parents(".total").children(".category").children("li:eq(1)").remove();  
   }

   function mod_change(mod){
       var m = $(mod).val();
       var ver_name = "version_"+m+"_0[]";
       var count_name = "counts_"+m+"_0[]";
       $(mod).parents(".total").children(".category").children("li").children(".version_ul").children("li").children(".version").attr('name',ver_name);
       $(mod).parents(".total").children(".category").children("li").children(".version_ul").children("li").children(".counts").attr('name',count_name);  
       $.ajax({
    	   type: "POST",
    	   url:"<?php echo  base_url();?>model/get_category",
    	   data: "mod_id="+m,
    	   success: function(msg){
        	   $(mod).parents(".total").children(".category").children("li").children(".category_id").html("");
        	   $(mod).parents(".total").children(".category").children("li").children(".category_id").html(msg);
    	   }
    	});
   }

   function cate_change(cate){
	   var m = $(cate).parents(".category").parents(".total").children(".mod").children(".mod_id").val();
	   var c = $(cate).val();
	   var ver_name = $(cate).parents("li").children(".version_ul").children("li").children(".version").attr('name');
	   var v = ver_name.split("_");
	   var ver_name = "version_"+m+"_"+c+"[]";
	   var count_name = "counts_"+m+"_"+c+"[]";
	   var num = $("#num").val();
	   var n = num.split("_");
	   var i = n[1];
	   var na = "version_"+i;
	   
	   var ver1 = $("#ver1").val();
	   var ver2 = $("#ver2").val();
	   var cou1 = $("#cou1").val();
	   var cou2 = $("#cou2").val();
	   var ver = ver1+" name='"+ver_name+"' "+ver2;
	   var cou = ver+cou1+" name='"+count_name+"'"+cou2;
	   $(cate).parents("li").children(".version_ul").children("li:eq(1)").html('');
	   $(cate).parents("li").children(".version_ul").children("li:eq(1)").html(cou);
	   $(cate).parents("li").children(".version_ul").children("li:eq(1)").children(".version").attr('id',na);
       var num = $("#num").val(na);

   }
</script>
<style>
<!--
  .total{clear:both;}
  .mod,.category{float:left;}
  .category{padding:0 10px 0 10px;margin:0px;}
  .category li{clear:both;}
  li{list-style-type:none;margin:10px 0 10px 0;}
  .version_ul li{margin-top:0px;}

  .category_id,.version_ul{float:left;}
  .del_category,.add_category,.add_version,.del_version,.add_mod,.del_mod{cursor:pointer;}
-->
</style>
<div id="center-column">
			<div class="top-bar">
				<a href="<?php echo  base_url();?>model/receive_add" class="button">新增</a>
				<h1>Contents</h1>
				<div class="breadcrumbs"><a href="#">首页</a> /<?php echo anchor('model/receive_add','添加接收记录');?></div>
			</div>
		  <input type="hidden" id="str" value="<li><select name='category_id[]' class='category_id' onchange='cate_change(this)'><option value=''>请选择资料类别</option></select><ul class='version_ul'><li><img src='<?php echo base_url();?>img/hr.gif' class='del_version' onclick='del(this)'/><img src='<?php echo base_url();?>img/add-icon.gif' class='add_version' onclick='add(this)'/></li> <li>版次:<input name='version_0_0[]' id='version_0' class='version'  onmouseover=InitCalendar(this,'style=calendar.css,close=true') readonly><img src='<?php echo site_url();?>img/cal.gif' align='absmiddle' onmouseover=InitCalendar(this,'style=calendar.css,close=true')>数量：<input type='text' class='counts' onclick='num(this)' onKeyUp=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/) onafterpaste=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/) name='counts[]' value='' /></li></ul></li>" />	
		  <input type="hidden" id="sttr" value="<div class='total'><div class='mod'>型号：<select name='mod_id[]' class='mod_id' onchange='mod_change(this)'><option value=''>请选择型号</option><?php foreach($mod as $k=>$val):?><option value='<?php echo $val->mod_id;?>' ><?php echo $val->name;?></option><?php endforeach;?></select><img src='<?php echo base_url();?>img/hr.gif' class='del_category' onclick='del_cate(this)'/><img src='<?php echo base_url();?>img/add-icon.gif' class='add_category' onclick='add_cate(this)'/></div><ul class='category'><li><select name='category_id[]' class='category_id' onchange='cate_change(this)'><option value=''>请选择资料类别</option></select><ul class='version_ul'><li><img src='<?php echo base_url();?>img/hr.gif' class='del_version' onclick='del(this)'/><img src='<?php echo base_url();?>img/add-icon.gif' class='add_version' onclick='add(this)'/></li> <li>版次:<input name='version_0_0[]' id='version_0' onmouseover=InitCalendar(this,'style=calendar.css,close=true') class='version'  readonly><img src='<?php echo site_url();?>img/cal.gif' align='absmiddle' onmouseover=InitCalendar(this,'style=calendar.css,close=true')>数量：<input type='text' class='counts' name='counts_0_0[]' onclick='num(this)' onKeyUp=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/) onafterpaste=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/) value='' /></li></ul></li></ul></div>" />
		  <input type="hidden" id="num" value="version_0" />
		  <input type="hidden" id="ver1" value="版次:<input " />
		  <input type="hidden" id="ver2" value="id='version_0' class='version' onmouseover=InitCalendar(this,'style=calendar.css,close=true') readonly><img src='<?php echo site_url();?>img/cal.gif' align='absmiddle' onmouseover=InitCalendar(this,'style=calendar.css,close=true')>" />
		  <input type="hidden" id="cou1" value='数量：<input type="text" class="counts"' />
		  <input type="hidden" id="cou2" value="onclick='num(this)' value='' onKeyUp=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/) onafterpaste=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/) />"	 />
		  <div class="table add_table">
				
				
				
			<?php if(isset($id)){echo form_open('model/receive_edit/'.$id);}else{echo form_open('model/receive_add');}?>	
			 <div class="receive">
			 <img src="<?php echo base_url();?>img/hr.gif" class="del_mod"/>
			 <img src="<?php echo base_url();?>img/add-icon.gif" class="add_mod"/>			 
				<div class="total">
				 <div class="mod">型号：<select name="mod_id[]" class="mod_id" onchange="mod_change(this)">
				          <option value="">请选择型号</option>
						 <?php foreach($mod as $k=>$val):?>
						  <option value="<?php echo $val->mod_id;?>" ><?php echo $val->name;?></option>
						 <?php endforeach;?>              
				       </select>
				       <img src="<?php echo base_url();?>img/hr.gif" class="del_category" onclick="del_cate(this)"/>
				       <img src="<?php echo base_url();?>img/add-icon.gif" class="add_category" onclick="add_cate(this)"/>
				  </div>
				       <ul class="category">
				           <li><select name="category_id[]" class="category_id" onchange="cate_change(this)">
				                     <option value="">请选择资料类别</option>
						             </select>
						             
						        <ul class="version_ul">
						            <li><img src='<?php echo base_url();?>img/hr.gif' class='del_version' onclick='del(this)'/><img src='<?php echo base_url();?>img/add-icon.gif' class='add_version' onclick='add(this)'/></li> 
						            <li>版次:<input name='version_0_0[]' id='version_0' class='version' onmouseover=InitCalendar(this,'style=calendar.css,close=true') readonly><img src='<?php echo site_url();?>img/cal.gif' align='absmiddle' onmouseover=InitCalendar(this,'style=calendar.css,close=true')>
					                                                     数量：<input type="text" class="counts" name="counts_0_0[]" onclick="num(this)" value="" onKeyUp="this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/)" onafterpaste="this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?'':this.value.match(/^[0-9]*[1-9][0-9]*$/)" />					                   
					                    </li>
						        </ul>     
						   </li>
				       </ul> 

				</div>
				
			</div>	
			  <div style="clear:both;text-align:center;padding-top:20px;">接收单号：<input type="text" name="codes" id="codes"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" id="submit" value="提交" /></div>	
			</form>	
				
	        <p>&nbsp;</p>
		  </div>
		</div>
	</div>
	<div id="footer"></div>
</div>



</body>
</html>
